'''
Author: your name
Date: 2021-04-20 10:26:47
LastEditTime: 2021-05-13 18:00:50
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: /tinyms/tinyms-api/apps/auth/organ/model.py
'''
from app import db

class Organ(db.Model):
    __tablename__ = 'sys_organ'
    organ_pk = db.Column(db.String,primary_key=True)
    organ_code = db.Column(db.String)
    organ_name= db.Column(db.String)
    organ_jc = db.Column(db.String)
    organ_phone = db.Column(db.String)
    organ_address = db.Column(db.String)
    organ_type = db.Column(db.String)
    organ_property = db.Column(db.String)
    organ_parent = db.Column(db.String)
    organ_status = db.Column(db.String)
    organ_time = db.Column(db.String)
    organ_qhdm = db.Column(db.String)
    organ_qhmc = db.Column(db.String)
    owner_sys = db.Column(db.String)

    def __repr__(self):
        return '<Organ %r>' % self.organ_pk
    

    def to_dict(items):
        lic = []
        for item in items:
            lic.append(
                {
                    'organ_pk' : item.organ_pk,
                    'organ_code' : item.organ_code,
                    'organ_name': item.organ_name,
                    'organ_jc' : item.organ_jc,
                    'organ_phone' : item.organ_phone,
                    'organ_address' : item.organ_address,
                    'organ_type' : item.organ_type,
                    'organ_property' : item.organ_property,
                    'organ_parent' : item.organ_parent,
                    'organ_status' : item.organ_status,
                    'organ_time' : item.organ_time,
                    'organ_qhdm' : item.organ_qhdm,
                    'organ_qhmc' : item.organ_qhmc,
                    'owner_sys' : item.owner_sys
                }
            )
        return lic
    
    def to_dict_ext(items):
        lic = {}
        for item in items:
            # lic.append(
            #     {
            #         item.organ_pk:item.organ_name
            #     }
            # )
            lic[item.organ_pk]=item.organ_name
        return lic